package com.yoomiito.app.ui.anyview.goodsinfo.bottom

import android.graphics.drawable.GradientDrawable
import android.view.View
import android.widget.LinearLayout
import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.BaseModel
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.base.BaseActivity
import com.yoomiito.app.isEmptyOr0
import com.yoomiito.app.model.bean.GoodsDetail
import com.yoomiito.app.net.NetErrorCode
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.removeDecimalPoint
import com.yoomiito.app.showToast
import com.yoomiito.app.ui.order.sureorder.singleGoods.BuyGoodsActivity
import com.yoomiito.app.ui.order.sureorder.singleGoods.NewSureOrderActivity
import com.yoomiito.app.utils.*
import com.yoomiito.app.widget.dialog.GetFreeGoodsTipDialog
import kotlinx.android.synthetic.main.view_goodsinfo_bottombar.view.*

class SddVipGoodsBottomBar(context: BaseActivity<*>) :BaseBottomBar(context){

    override fun getLayoutId(): Int = R.layout.view_goodsinfo_bottombar

    override fun getParentView(): LinearLayout = this

    override fun initView(goodsDetail: GoodsDetail) {
        val drawable = leftBtn.background as GradientDrawable
        val radius = DensityUtil.dp2px(24f).toFloat()
        drawable.cornerRadius = radius
        val drawable1 = rightBtn.background as GradientDrawable
        drawable1.cornerRadius = radius
        goHome.setOnClickListener {
            RouterUtils.toMain(context,0)
        }

        leftBtn.setOnClickListener {
            if (App.mAppConfig.isLogin){
                showShareDialog()
            }else{
//                AllUtils.toLogin(context, AllCode.LoginIn)
                LoginUtils.toOneKeyLogin(context)
            }
        }
        if (App.mAppConfig.isLogin&&UserInfoConfig.getUser().three_role_id.toInt()>=Type.LevelType.SDD_VIP_10){
            rightBtn.visibility = View.GONE
            rightBtnLl.visibility = View.GONE
        }
        rightBtn.setOnClickListener {
            if (App.mAppConfig.isLogin){
                BuyGoodsActivity.start(context, goodsDetail, Type.GoodsType.GiveMore)
//                NewSureOrderActivity.start(context,goodsDetail)
            }else{
                LoginUtils.toOneKeyLogin(context)
            }
        }
        leftBtnBottomTv.visibility =if(!App.mAppConfig.isLogin||goodsDetail.share_money.isEmptyOr0()||UserInfoConfig.getUser().three_role_id.toInt()<Type.LevelType.SDD_VIP_10) View.GONE else View.VISIBLE
        leftBtnBottomTv.text = "赚${goodsDetail.share_money.removeDecimalPoint()}元"
        rightBtnBottomTv.visibility =  View.GONE
    }
}